//
//  RegisterViewController.m
//  shopping
//
//  Created by 徐双 on 2017/9/3.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "RegisterViewController.h"


@interface RegisterViewController ()<UITextFieldDelegate>
{

    NSString * type;
    UIView *viewOfJdr;//手机接点人
    NSString *PhoneLeftJ;//手机左边接点人
    NSString *phoneRightJ;//手机右边接点人
    
    NSString *youXiangLeftJ;//邮箱左边接点人
    NSString *youXiangRightJ;//邮箱右边接点人
    UIView *viewYouXiangJDR;//邮箱接点人View
    

}

//手机注册的view
@property (weak, nonatomic) IBOutlet UIView *iphoneView;

@property (weak, nonatomic) IBOutlet UIView *iphoneYellowView;
//输入手机号
@property (weak, nonatomic) IBOutlet UITextField *inputPhoneNum;
@property (weak, nonatomic) IBOutlet UITextField *shoujiYongHM;//手机用户名
@property (weak, nonatomic) IBOutlet UITextField *qingQueRenShouJiMiM;//手机确认密码



//输入密码
@property (weak, nonatomic) IBOutlet UITextField *inputPassword;
@property (weak, nonatomic) IBOutlet UIButton *phoneYZM;//手机验证码

//输入推荐人
@property (weak, nonatomic) IBOutlet UITextField *inputRecoPerson;

///////////////
@property (nonatomic, strong) UILabel *shoujiJieDian;//手机接点人
@property (nonatomic, strong) UIButton *buttonLeftJdr;//手机左边接点人
@property (nonatomic, strong) UIButton *buttonRightJD;//手机右边接点人




//验证码

@property (weak, nonatomic) IBOutlet UITextField *verIfyCode;

@property(nonatomic,strong)NSMutableDictionary *productParams1;

//邮箱注册的view

@property (weak, nonatomic) IBOutlet UIView *emailBoxView;

@property (weak, nonatomic) IBOutlet UIView *emailBoxYellowView;

//输入邮箱账号
@property (weak, nonatomic) IBOutlet UITextField *inputEmailAcoount;
//输入邮箱登录密码
@property (weak, nonatomic) IBOutlet UITextField *inputEmailPassword;
//输入邮箱推荐人
@property (weak, nonatomic) IBOutlet UITextField *inputEmailRecoPerson;


@property(nonatomic,strong)NSMutableDictionary *productParams2;

@property (nonatomic, strong) UILabel *youXiangJieDian;//邮箱接点人
@property (nonatomic, strong) UIButton *youXiangLeftJdr;//邮箱左边接点人
@property (nonatomic, strong) UIButton *youXiangRightJD;//邮箱右边接点人
@property (weak, nonatomic) IBOutlet UITextField *youXiangYHM;//邮箱用户名
@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UIButton *weiBo;
@property (weak, nonatomic) IBOutlet UIButton *qq;
@property (weak, nonatomic) IBOutlet UIButton *weiXin;


//注册时获取接点人参数
@property(nonatomic,assign)NSInteger left_uid;
@property(nonatomic,assign)NSInteger  right_uid;
@property (weak, nonatomic) IBOutlet UIButton *youXiangYinChangBtn;

@end

@implementation RegisterViewController

- (void)viewWillAppear:(BOOL)animated{
    
    
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
    
    
}
//获取验证码
- (IBAction)huoQuYZM:(UIButton *)sender {
 
//    NSMutableDictionary *productParamsss=[[NSMutableDictionary alloc]init];
//    //    NSString *token = [PublicFunction getConfigWithKey:@"token"];
//    
//    
//    [productParamsss setValue:self.inputPhoneNum.text forKey:@"phone"];
//    
//    [[MNetworkHandler sharedInstance]conURL:adminLoginSendPhone networkType:NetWorkPOST params:productParamsss delegate:nil showHUD:NO successBlock:^(id returnData) {
//        
//        
//        if ([[returnData objectForKey:@"code"]intValue]==1) {
//            
//          [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
//            
//            
//        }
//        
//        else {
//            
//            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
//            
//        }
//        
//    } failureBlock:^(NSError *error) {
//        
//        NSLog(@"%@",error);
//        
////        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
//        
//    }];

    
    NSMutableDictionary *productParamsss=[[NSMutableDictionary alloc]init];
    //    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    
    
    [productParamsss setValue:self.inputPhoneNum.text forKey:@"phone"];
    
    [[MNetworkHandler sharedInstance]conURL:adminLoginSendPhone
                                networkType:NetWorkPOST
                                     params:productParamsss
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   
                                   if ([returnData[@"code"] intValue] == 1) {
                                       
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                       
                                       __block int timeout=60; //倒计时时间
                                       dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                                       dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
                                       dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
                                       
                                       dispatch_source_set_event_handler(_timer, ^{
                                           
                                           if(timeout<=0){ //倒计时结束，关闭
                                               
                                               dispatch_source_cancel(_timer);
                                               dispatch_async(dispatch_get_main_queue(), ^{
                                                   //设置界面的按钮显示 根据自己需求设置
                                                   [self.phoneYZM setTitle:@"发送验证码" forState:UIControlStateNormal];
                                                   
                                                   self.phoneYZM.userInteractionEnabled = YES;
                                               });
                                           }else{
                                               int seconds = timeout % 61;
                                               
                                               NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
                                               dispatch_async(dispatch_get_main_queue(), ^{
                                                   //设置界面的按钮显示 根据自己需求设置
                                                   //NSLog(@"____%@",strTime);
                                                   [UIView beginAnimations:nil context:nil];
                                                   [UIView setAnimationDuration:1];
                                                   [self.phoneYZM setTitle:[NSString stringWithFormat:@"%@秒",strTime] forState:UIControlStateNormal];
                                                   [UIView commitAnimations];
                                                   self.phoneYZM.userInteractionEnabled = NO;
                                               });
                                               timeout--;
                                           }
                                       });
                                       dispatch_resume(_timer);
                                   }else{
                                       
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                   }
                                   
                               }
                               failureBlock:^(NSError *error) {
                                   NSLog(@"%@",error);
                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
                               }];

    
    
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.label1.hidden = YES;
    self.weiBo.hidden = YES;
    self.qq.hidden = YES;
    self.weiXin.hidden = YES;
  
    self.youXiangYinChangBtn.hidden = YES;
    
    type = @"1";
    [self setUpNav];
    self.inputPhoneNum.keyboardType = UIKeyboardTypeNumberPad;
    [self.verIfyCode addTarget:self action:@selector(textFiledLengthControl:) forControlEvents:UIControlEventTouchUpInside];
    self.inputPhoneNum.delegate = self;
    
    
   
    

}

//限制验证码长度

-(void)textFiledLengthControl:(UITextField *)textField{

    if (textField == self.verIfyCode) {
        
        if (textField.text.length > 4) {
            
            textField.text = [textField.text substringToIndex:4];
        }
    }


}
//添加UI
-(void)setUpNav{

    //添加注册按钮
    UIButton *buttonAdd = [[UIButton alloc] init];
    
    buttonAdd.frame = CGRectMake(13, 0, 80, 40);
    [buttonAdd setTitle:@"返回登录" forState:UIControlStateNormal];
    [buttonAdd addTarget:self action:@selector(returnLoginClick) forControlEvents:UIControlEventTouchUpInside];
    UIColor * color = getColor(@"222222");
    [buttonAdd setTitleColor:color forState:UIControlStateNormal];
    buttonAdd.titleLabel.font = [UIFont systemFontOfSize:15];
    UIBarButtonItem *leftItme = [[UIBarButtonItem alloc]initWithCustomView:buttonAdd];
    self.navigationItem.leftBarButtonItem = leftItme;
    self.emailBoxView.hidden = YES;
    self.emailBoxYellowView.hidden = YES;
    self.iphoneView.hidden = NO;
    self.iphoneYellowView.hidden = NO;
   //手机注册修改
    UIButton *buttonOfPhone = [[UIButton alloc] init];
    [self.iphoneView addSubview:buttonOfPhone];
    [buttonOfPhone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.inputRecoPerson.mas_top);
        make.left.equalTo(self.inputRecoPerson.mas_right);
        make.bottom.equalTo(self.inputRecoPerson.mas_bottom);
        make.right.equalTo(self.iphoneView);
        
    }];
    [buttonOfPhone setTitle:@"确认" forState:UIControlStateNormal];
    [buttonOfPhone setTitleColor:getColor(@"222222") forState:UIControlStateNormal];
    buttonOfPhone.backgroundColor = [UIColor colorWithRed:240 / 255.0f green:241/ 255.0f blue:242 / 255.0f alpha:1];
    buttonOfPhone.titleLabel.font = [UIFont systemFontOfSize:14];
    
    [buttonOfPhone addTarget:self action:@selector(tuijianClick) forControlEvents:UIControlEventTouchUpInside];
    
    self.shoujiJieDian = [[UILabel alloc] init];
    [self.iphoneView addSubview:self.shoujiJieDian];
    
    [self.shoujiJieDian mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.inputRecoPerson.mas_bottom).with.offset(7);
        make.left.equalTo(self.iphoneView);
        make.right.equalTo(self.iphoneView);
        make.height.offset(35);
        
    }];
    self.shoujiJieDian.backgroundColor = [UIColor colorWithRed:240 / 255.0f green:241/ 255.0f blue:242 / 255.0f alpha:1];
    
    //邮箱注册修改
    
    UIButton *buttonOfYouXiang = [[UIButton alloc] init];
    [self.emailBoxView addSubview:buttonOfYouXiang];
    [buttonOfYouXiang mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.inputEmailRecoPerson.mas_top);
        make.left.equalTo(self.inputEmailRecoPerson.mas_right);
        make.bottom.equalTo(self.inputEmailRecoPerson.mas_bottom);
        make.right.equalTo(self.emailBoxView);
        
    }];
    [buttonOfYouXiang setTitle:@"确认" forState:UIControlStateNormal];
    [buttonOfYouXiang setTitleColor:getColor(@"222222") forState:UIControlStateNormal];
    buttonOfYouXiang.backgroundColor = [UIColor colorWithRed:240 / 255.0f green:241/ 255.0f blue:242 / 255.0f alpha:1];
    buttonOfYouXiang.titleLabel.font = [UIFont systemFontOfSize:14];
    
    [buttonOfYouXiang addTarget:self action:@selector(youXiangTuiJian) forControlEvents:UIControlEventTouchUpInside];
    
    self.youXiangJieDian = [[UILabel alloc] init];
    [self.emailBoxView addSubview:self.youXiangJieDian];
    
    [self.youXiangJieDian mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.inputEmailRecoPerson.mas_bottom).with.offset(7);
        make.left.equalTo(self.emailBoxView);
        make.right.equalTo(self.emailBoxView);
        make.height.offset(35);
        
    }];
    self.youXiangJieDian.backgroundColor = [UIColor colorWithRed:240 / 255.0f green:241/ 255.0f blue:242 / 255.0f alpha:1];
    
    
    
    
    
    
    
    
    
    
//    UIButton *buttonOfXZ = [[UIButton alloc] init];
//    [self.iphoneView addSubview:buttonOfXZ];
//    
//    [buttonOfXZ mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.shoujiJieDian.mas_centerY);
//        make.right.equalTo(self.shoujiJieDian.mas_right).with.offset(-30);
//        
//    }];
//    [buttonOfXZ setImage:[UIImage imageNamed:@"向下实心箭头"] forState:UIControlStateNormal];
//    
//    [buttonOfXZ addTarget:self action:@selector(changeJieDR) forControlEvents:UIControlEventTouchUpInside];
    
    
}

//手机选择接点人
- (void)changeJieDR{

    viewOfJdr = [[UIView alloc] init];
    [self.iphoneView addSubview:viewOfJdr];
    viewOfJdr.userInteractionEnabled = YES;
    self.iphoneView.userInteractionEnabled = YES;
    
    [viewOfJdr mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.inputRecoPerson.mas_bottom).with.offset(7);
        make.left.equalTo(self.iphoneView);
        make.right.equalTo(self.iphoneView);
        make.height.offset(80);
        
    }];
    
    viewOfJdr.backgroundColor = [UIColor colorWithRed:240 / 255.0f green:241/ 255.0f blue:242 / 255.0f alpha:1];
    
    self.buttonLeftJdr = [[UIButton alloc] init];
    [viewOfJdr addSubview:self.buttonLeftJdr];
    [self.buttonLeftJdr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewOfJdr);
        make.left.equalTo(viewOfJdr);
        make.right.equalTo(viewOfJdr);
        make.height.offset(35);
        
    }];
    [self.buttonLeftJdr setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.buttonLeftJdr addTarget:self action:@selector(changeLeftJdren:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.buttonRightJD = [[UIButton alloc] init];
    [viewOfJdr addSubview:self.buttonRightJD];
    [self.buttonRightJD mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.buttonLeftJdr.mas_bottom).with.offset(3);
        make.left.equalTo(viewOfJdr);
        make.right.equalTo(viewOfJdr);
        make.height.offset(35);
        
    }];
    [self.buttonRightJD setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [self.buttonRightJD addTarget:self action:@selector(changeRightJdren:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.buttonRightJD addTarget:self action:@selector(changeRightJdren:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
}
//
- (void)changeLeftJdren:(UIButton *)sender{

    self.shoujiJieDian.text = PhoneLeftJ;
    self.shoujiJieDian.tag = sender.tag;
    
    
    [viewOfJdr removeFromSuperview];
    
}
- (void)changeRightJdren:(UIButton *)sender{

    self.shoujiJieDian.text = phoneRightJ;
    
    self.shoujiJieDian.tag = sender.tag;
    
    [viewOfJdr removeFromSuperview];
    
}
//邮箱选择接点人

- (void)youXiangJDR{

    viewYouXiangJDR = [[UIView alloc] init];
    [self.emailBoxView addSubview:viewYouXiangJDR];
    [viewYouXiangJDR mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.inputEmailRecoPerson.mas_bottom).with.offset(7);
        make.left.equalTo(self.emailBoxView);
        make.right.equalTo(self.emailBoxView);
        make.height.offset(80);
        
    }];
    
    viewYouXiangJDR.backgroundColor = [UIColor colorWithRed:240 / 255.0f green:241/ 255.0f blue:242 / 255.0f alpha:1];
    
    self.youXiangLeftJdr = [[UIButton alloc] init];
    [viewYouXiangJDR addSubview:self.youXiangLeftJdr];
    [self.youXiangLeftJdr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(viewYouXiangJDR);
        make.left.equalTo(viewYouXiangJDR);
        make.right.equalTo(viewYouXiangJDR);
        make.height.offset(40);
        
    }];
    [self.youXiangLeftJdr setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.youXiangLeftJdr addTarget:self action:@selector(changeYouLeftJdren:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    self.youXiangRightJD = [[UIButton alloc] init];
    [viewYouXiangJDR addSubview:self.youXiangRightJD];
    [self.youXiangRightJD mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.youXiangLeftJdr.mas_bottom);
        make.left.equalTo(viewYouXiangJDR);
        make.right.equalTo(viewYouXiangJDR);
        make.height.offset(40);
        
    }];
    [self.youXiangRightJD setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.youXiangRightJD addTarget:self action:@selector(changeYouRightJdren:) forControlEvents:UIControlEventTouchUpInside];

    
    
    


}
- (void)changeYouLeftJdren:(UIButton *)sender{

    
    self.youXiangJieDian.text = youXiangLeftJ;
    self.youXiangJieDian.tag = sender.tag;
    
    
    [viewYouXiangJDR removeFromSuperview];
}

- (void)changeYouRightJdren:(UIButton *)sender{
    
    
    self.youXiangJieDian.text = youXiangRightJ;
    self.youXiangJieDian.tag = sender.tag;
    
    
    [viewYouXiangJDR removeFromSuperview];
}


//邮箱 接口获取接点人
- (void)youXiangTuiJian{

    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.tag = 500;
    
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = YES;
    
    NSMutableDictionary *productParams = [[NSMutableDictionary alloc]init];
    //[productParams setValue: @"admin" forKey:@"pname"];
    [productParams setValue:self.inputEmailRecoPerson.text forKey:@"pname"];
    
    [[MNetworkHandler sharedInstance] conURL:registerJieUrl
                                 networkType:NetWorkPOST
                                      params:productParams
                                    delegate:nil
                                     showHUD:NO
                                successBlock:^(id returnData) {
                                    if ([[returnData objectForKey:@"code"]intValue] == 1){
                                        
                                        
                                        [self youXiangJDR];
                                        
                                        
                                        NSMutableDictionary *tokenD = [returnData objectForKey:@"data"];
                                        
                                        //                                        self.shoujiJieDian.text = [tokenD objectForKey:@"left"];
                                        
                                        PhoneLeftJ =[tokenD objectForKey:@"left"];
                                        phoneRightJ = [tokenD objectForKey:@"right"];
                                        
                                        
                                        self.buttonLeftJdr.tag = [[tokenD objectForKey:@"left_uid"] integerValue];
                                        NSString *strLetf = @"A区";
                                        if ([[tokenD objectForKey:@"left_uid"] length] == 0) {
                                            [self.buttonLeftJdr setTitle:[strLetf stringByAppendingString:@"无"] forState:UIControlStateNormal];
                                            
                                        }else {
                                            
                                            
                                            [self.buttonLeftJdr setTitle:[strLetf stringByAppendingString:[tokenD objectForKey:@"left"]] forState:UIControlStateNormal];
                                        }
                                        
                                        self.buttonRightJD.tag = [[tokenD objectForKey:@"right_uid"] integerValue];
                                        
                                        NSString *strRight = @"B区";
                                        if ([[tokenD objectForKey:@"right"] length] == 0) {
                                            [self.buttonRightJD setTitle:[strRight stringByAppendingString:@"无"] forState:UIControlStateNormal];
                                            
                                        }else {
                                            
                                            
                                            [self.buttonRightJD setTitle:[strRight stringByAppendingString:[tokenD objectForKey:@"right"]] forState:UIControlStateNormal];
                                        }

                                        
                                        
                                        [hud removeFromSuperview];
                                        
                                    }else{
                                        
                                        [hud removeFromSuperview];
                                         [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                    }
                                    
                                    
                                } failureBlock:^(NSError *error) {
                                    
                                    [hud removeFromSuperview];
                                    NSLog(@"%@",error);
//                                    [PublicFunction showAlert:nil message:@"没有连接网络" duration:1.0f];
                                }];

    
    
    
    
    

}


//手机 接口获取接点人
- (void)tuijianClick{
    
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.tag = 500;
    
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = YES;
    
    NSMutableDictionary *productParams = [[NSMutableDictionary alloc]init];
    //[productParams setValue: @"admin" forKey:@"pname"];
    [productParams setValue:self.inputRecoPerson.text forKey:@"pname"];
    
    [[MNetworkHandler sharedInstance] conURL:registerJieUrl
                                 networkType:NetWorkPOST
                                      params:productParams
                                    delegate:nil
                                     showHUD:NO
                                successBlock:^(id returnData) {
                                    if ([[returnData objectForKey:@"code"]intValue] == 1){
                                       
                                        
                                        [self changeJieDR];
                                        
                                        
                                        NSMutableDictionary *tokenD = [returnData objectForKey:@"data"];
                                        
//                                        self.shoujiJieDian.text = [tokenD objectForKey:@"left"];
                                        
                                        PhoneLeftJ =[tokenD objectForKey:@"left"];
                                        phoneRightJ = [tokenD objectForKey:@"right"];
                                        
                                        
                                        self.buttonLeftJdr.tag = [[tokenD objectForKey:@"left_uid"] integerValue];
                                        NSString *strLetf = @"A区";
                                        if ([[tokenD objectForKey:@"left"] length] == 0) {
                                            [self.buttonLeftJdr setTitle:[strLetf stringByAppendingString:@"无"] forState:UIControlStateNormal];
                                            
                                        }else {
                                        
                                            
                                            [self.buttonLeftJdr setTitle:[strLetf stringByAppendingString:[tokenD objectForKey:@"left"]] forState:UIControlStateNormal];
                                        }
      
                                        self.buttonRightJD.tag = [[tokenD objectForKey:@"right_uid"] integerValue];
                                
                                        NSString *strRight = @"B区";
                                        if ([[tokenD objectForKey:@"right"] length] == 0) {
                                            [self.buttonRightJD setTitle:[strRight stringByAppendingString:@"无"] forState:UIControlStateNormal];
                                            
                                        }else {
                                        
                                            [self.buttonRightJD setTitle:[strRight stringByAppendingString:[tokenD objectForKey:@"right"]] forState:UIControlStateNormal];
                                        }
                                        
                                        
                                        [hud removeFromSuperview];
                                        
                                    }else{
                                        
                                        [hud removeFromSuperview];
                                         [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                    }
                                    
                                    
                                } failureBlock:^(NSError *error) {
                                    
                                    [hud removeFromSuperview];
                                    NSLog(@"%@",error);
//                                    [PublicFunction showAlert:nil message:@"没有连接网络" duration:1.0f];
                                }];

    
}


-(void)returnLoginClick{
    
    NSLog(@"ddff");

    [self.navigationController popViewControllerAnimated:YES];

}

- (IBAction)iphoneBtnClik:(id)sender {
    
    self.emailBoxView.hidden = YES;
    self.emailBoxYellowView.hidden = YES;
    self.iphoneView.hidden = NO;
    self.iphoneYellowView.hidden = NO;
    
    type = @"1";
    
}

    

- (IBAction)emailBoxBtnClick:(id)sender {
    
    self.iphoneView.hidden = YES;
    self.iphoneYellowView.hidden = YES;
    self.emailBoxView.hidden = NO;
    self.emailBoxYellowView.hidden = NO;
    
    type = @"2";

}

//手机注册密码可不可见

- (IBAction)iponeEyeClick:(UIButton *)sender {
    
    sender.selected = !sender.selected;
    if (sender.selected) {
        
        self.inputPassword.secureTextEntry=YES;
    }else {
        
        self.inputPassword.secureTextEntry=NO;
    }

    
}

//邮箱密码可不可见

- (IBAction)emailEyeClick:(UIButton *)sender {
    
    sender.selected = !sender.selected;
    if (sender.selected) {
        
        self.inputEmailPassword.secureTextEntry=YES;
    }else {
        
        self.inputEmailPassword.secureTextEntry=NO;
    }
    
}


- (IBAction)registerBtnClick:(id)sender {
    
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.tag = 500;
    
    //提示文本
    hud.labelText = @"正在加载...";
    //是否有遮罩
    hud.dimBackground = YES;
    if ([type isEqualToString:@"1"]) {
        
        if ([self.qingQueRenShouJiMiM.text isEqualToString:_inputPassword.text]) {
            
            NSMutableDictionary *productParams1 = [[NSMutableDictionary alloc]init];
            [productParams1 setValue: _inputPhoneNum.text forKey:@"userPhone"];
            [productParams1 setValue: _inputPassword.text forKey:@"loginPwd"];
            [productParams1 setValue: _inputRecoPerson.text forKey:@"pid"];
            [productParams1 setValue:self.shoujiYongHM.text forKey:@"loginName"];
            
            NSString *strPhone = [NSString stringWithFormat:@"%ld", (long)self.shoujiJieDian.tag];
            [productParams1 setValue: strPhone forKey:@"point_id"];
            [productParams1 setValue: self.verIfyCode.text forKey:@"mobileCode"];
            [productParams1 setValue:@"3" forKey:@"nameType"];
            [productParams1 setValue:@"1" forKey:@"protocol"];
            
            [[MNetworkHandler sharedInstance] conURL:registerUrl
                                         networkType:NetWorkPOST
                                              params:productParams1
                                            delegate:nil
                                             showHUD:NO
                                        successBlock:^(id returnData) {
                                            if ([[returnData objectForKey:@"code"]intValue] == 1){
                                                [hud removeFromSuperview];
                                                
                                                [PublicFunction showAlert:nil message:@"注册成功" duration:1.0f];
                                                
                                                [self.navigationController popViewControllerAnimated:YES];
                                                
                                                
                                                
//                                                NSMutableDictionary *tokenD = [returnData objectForKey:@"data"];
//                                                
//                                                
//                                                [PublicFunction saveConfig:[tokenD objectForKey:@"userId"] forKey:@"userId"];
//                                                [PublicFunction saveConfig:[tokenD objectForKey:@"token"] forKey:@"token"];
//                                                
//                                                UINavigationBar *bar = [UINavigationBar appearance];
//                                                
//                                                
//                                                [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
//                                                
//                                                //设置显示的颜色
//                                                
//                                                bar.barTintColor =[ZJCModel colorWithString:@"ffffff"];
//                                                
//                                                //设置字体颜色
//                                                
//                                                bar.tintColor = [UIColor whiteColor];
//                                                
//                                                
//                                                [bar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
//                                                MyTabBarController *barController = [[MyTabBarController alloc] init];
//                                                // TAB BAR
//                                                
//                                                [self presentViewController:barController animated:YES completion:nil];
                                                
                                            }else{
                                                
                                                [hud removeFromSuperview];
                                                [PublicFunction showAlert:nil message:@"注册失败" duration:1.0f];
                                            }
                                            
                                            
                                        } failureBlock:^(NSError *error) {
                                            
                                            [hud removeFromSuperview];
                                            NSLog(@"%@",error);
                                            //                                        [PublicFunction showAlert:nil message:@"没有连接网络" duration:1.0f];
                                        }];
            

            
            
            
        }else {
        
            [PublicFunction showAlert:nil message:@"请输入正确密码" duration:1.0f];
            
            [hud removeFromSuperview];
        }
        
        
        
    }else{
        NSMutableDictionary *productParams2 = [[NSMutableDictionary alloc]init];
        [productParams2 setValue: _inputEmailAcoount.text forKey:@"userEmail"];
        [productParams2 setValue: _inputEmailPassword.text forKey:@"loginPwd"];
        [productParams2 setValue: _inputEmailRecoPerson.text forKey:@"pid"];
      
        [productParams2 setValue:self.youXiangYHM.text forKey:@"loginName"];
        NSString *strPhone = [NSString stringWithFormat:@"%ld", (long)self.youXiangJieDian.tag];
        [productParams2 setValue: strPhone forKey:@"point_id"];

        [productParams2 setValue:@"1" forKey:@"nameType"];
        [productParams2 setValue:@"1" forKey:@"protocol"];
        
        [[MNetworkHandler sharedInstance] conURL:registerUrl
                                     networkType:NetWorkPOST
                                          params:productParams2
                                        delegate:nil
                                         showHUD:NO
                                    successBlock:^(id returnData) {
                                        if ([[returnData objectForKey:@"code"]intValue] == 1){
                                            [hud removeFromSuperview];
                                            
                                            NSMutableDictionary *tokenD = [returnData objectForKey:@"data"];
                                            
                                            
                                            [PublicFunction saveConfig:[tokenD objectForKey:@"userId"] forKey:@"userId"];
                                            [PublicFunction saveConfig:[tokenD objectForKey:@"token"] forKey:@"token"];
                                            
                                            NSLog(@"status == %@",[PublicFunction getConfigWithKey:@"status"]);
                                            NSLog(@"msg == %@",[PublicFunction getConfigWithKey:@"msg"]);
                                            
                                            UINavigationBar *bar = [UINavigationBar appearance];
                                            
                                            
                                            [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
                                            
                                            //设置显示的颜色
                                            
                                            bar.barTintColor =[ZJCModel colorWithString:@"ffffff"];
                                            
                                            //设置字体颜色
                                            
                                            bar.tintColor = [UIColor whiteColor];
                                            
                                            
                                            [bar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
                                            MyTabBarController *barController = [[MyTabBarController alloc] init];
                                            // TAB BAR
                                            
                                            [self presentViewController:barController animated:YES completion:nil];
                                            
                                        }else{
                                            
                                            [hud removeFromSuperview];
                                            [PublicFunction showAlert:nil message:@"注册失败" duration:1.0f];
                                        }
                                        
                                        
                                    } failureBlock:^(NSError *error) {
                                        
                                        [hud removeFromSuperview];
                                        NSLog(@"%@",error);
//                                        [PublicFunction showAlert:nil message:@"没有连接网络" duration:1.0f];
                                    }];

        
        
        
    }
    
 
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    
    if (textField == _inputPhoneNum) {
        
        if (string.length == 0) return YES;
        
        NSInteger existedLength = textField.text.length;
        NSInteger selectedLength = range.length;
        NSInteger replaceLength = string.length;
        
        if (existedLength - selectedLength + replaceLength > 11) {
            return NO;
        }
    }
    
    //    if (textField == _YZMTextF) {
    //
    //        if (string.length == 0) return YES;
    //
    //        NSInteger existedLength = textField.text.length;
    //        NSInteger selectedLength = range.length;
    //        NSInteger replaceLength = string.length;
    //
    //        if (existedLength - selectedLength + replaceLength > 4) {
    //            return NO;
    //        }
    //    }
    //
    //
    //    NSCharacterSet *cs;
    //
    //    if (textField == _passTF ) {
    //
    //        cs = [[NSCharacterSet characterSetWithCharactersInString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"] invertedSet];
    //        NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    //        BOOL basicTest = [string isEqualToString:filtered];
    //        if(!basicTest)  {
    //            return NO;
    //        }
    //
    //        if (string.length == 0) return YES;
    //
    //        NSInteger existedLength = textField.text.length;
    //        NSInteger selectedLength = range.length;
    //        NSInteger replaceLength = string.length;
    //
    //        if (existedLength - selectedLength + replaceLength > 16) {
    //            return NO;
    //        }
    //    }
    
    return YES;
}



@end
